package cc.sends;

import java.text.DecimalFormat;
import java.util.List;

/**
 * @ Description : FCFS Algorithm
 * @ Author : ChristosC
 * @ Date : 2020/12/16 21:01
 */
public class FCFS {
    List<Track> tracks;
    Track currTrack;
    float averageDistance;

    public void init(List<Track> tracks,Track currTrack){
        this.tracks = tracks;
        this.currTrack = currTrack;
        averageDistance = 0;
    }
    public void start(){
        int sumDistance = 0;
        DecimalFormat df = new DecimalFormat("#0.00");
        // 取出队头计算移动距离 并输出磁道编号和移动距离
        for(Track track : tracks){
            track.setDistanceToCurrTrack(Math.abs(currTrack.getTrackNum() - track.getTrackNum()));
            currTrack = track;
            sumDistance += track.getDistanceToCurrTrack();
            System.out.println(track.getTrackNum()+ "\t" +track.getDistanceToCurrTrack());
        }
        averageDistance = (float) sumDistance/tracks.size();
        System.out.println("平均寻道长度："+df.format(averageDistance));
    }

}
